﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KPIS.GERP.GAMS.DAL;
using KPIS.GERP.GAMS.MODEL;
using KPIS.DBM;
using System.Data;
using System.Configuration;

namespace KPIS.GERP.GAMS.DAL
{
    public class D_ACM_POPUP
    {
        DBManager dbManager = new DBManager(SystemInfo._DataProvider, ConfigurationSettings.AppSettings["ConnectionString"].ToString());
        ConvertNullable cn = new ConvertNullable();

        public IList<M_ACM_MAS_Account> GetList(Nullable<int> version_seq)
        {
            DataRowCollection drc = null;
            IList<M_ACM_MAS_Account> infoList = new List<M_ACM_MAS_Account>();
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(1);
                dbManager.AddParameters(0, "@version_seq", version_seq);
                string strSQL = "SELECT account_seq,account_code,upper_account_seq,account_name,account_descr "
                               + " ,version_seq ,concat(coalesce(account_code, ''), ' : ', coalesce(account_name, '')) as acc_name  "
                               + " FROM acm_mas_account "
                               + " WHERE record_status = 'U' and "
                               + " version_seq = @version_seq "
                               + " ORDER BY account_code";

                drc = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0].Rows;
                if (drc.Count > 0)
                {
                    for (int i = 0; i < drc.Count; i++)
                    {
                        M_ACM_MAS_Account info = new M_ACM_MAS_Account();
                        info.account_seq = Convert.ToInt32(drc[i]["account_seq"]);
                        info.account_code = drc[i]["account_code"].ToString();
                        info.upper_account_seq = cn.ConvertNullInt(drc[i]["upper_account_seq"]);
                        info.account_name = drc[i]["account_name"].ToString();
                        info.account_desc = drc[i]["account_descr"].ToString();
                        info.version_seq = drc[i]["version_seq"].ToString();
                        info.upper_account_name = drc[i]["acc_name"].ToString();
                        infoList.Add(info);
                    }
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }

            return infoList;

        }
    }
}
